package com.google.code.training_java_basic.basics;

import java.util.Scanner;

/**
 *  Class Calendar prints out the day of the week for a given day (1..31), month (1..12) and year.
 *  For example, for a given input "10 October 2010" it should print to the screen "Sunday" */

public class Calendar {
	
	final static String[] DAYS_OF_WEEK   = { "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};

	public static int getMonthId (String monthName) {
		
		// Array offset, january - 1st month etc.
		int offset = 1;						
		int result = 0;
		String[] monthNames = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November",  "December"};		
		
		for (int monthId=0; monthId < monthNames.length; monthId++){
			if(monthNames[monthId].equalsIgnoreCase(monthName)) {
				result = monthId + offset;
				break;
			}
		}
		return result;
		
	}

	public static void main(String[] args) {	

    	Scanner scanner = new Scanner(System.in);
    	System.out.println("Enter  date in format dd-MonthName-yyyy");
    	String[] currentDate = scanner.nextLine().split("-");
    	scanner.close();

    	int dayOfMonth = Integer.parseInt(currentDate[0]);
		int monthOfYear = getMonthId(currentDate[1]);
		int year = Integer.parseInt(currentDate[2]);
		
        if (monthOfYear < 3) {
        	monthOfYear += 12;
        	year -= 1;
        }
        
		int yearOfCentury = year % 100;
		int century = year/100;
		
		int dayOfWeek = ((dayOfMonth + (((monthOfYear + 1) * 26) / 10) + yearOfCentury + (yearOfCentury / 4) + (century / 4)) 
						+  (5 * century)) % 7;
		
		System.out.println(DAYS_OF_WEEK[dayOfWeek]);		
		  
	}
}
